﻿//抽象类管理函数
public abstract class Shape
{
    public abstract double CalculateArea();
    public abstract bool IsValid();
}

//矩形派生类
public class Rectangle : Shape
{
    public double Length { get; set; }
    public double Width { get; set; }

    public Rectangle(double length, double width)
    {
        Length = length;
        Width = width;
    }

    //具体实现
    public override double CalculateArea() => IsValid() ? Length * Width : 0;
    public override bool IsValid() => Length > 0 && Width > 0;
}

//正方形派生类
public class Square : Shape
{
    public double Side { get; set; }

    public Square(double side) => Side = side;

    //具体实现
    public override double CalculateArea() => IsValid() ? Side * Side : 0;
    public override bool IsValid() => Side > 0;
}

//三角形类
public class Triangle : Shape
{
    public double A { get; set; }
    public double B { get; set; }
    public double C { get; set; }

    public Triangle(double a, double b, double c)
    {
        A = a;
        B = b;
        C = c;
    }

    public override double CalculateArea()
    {
        if (!IsValid()) 
            return 0;
        //使用海伦公式避免处理三角形形状问题
        double s = (A + B + C) / 2;
        return Math.Sqrt(s * (s - A) * (s - B) * (s - C));
    }

    public override bool IsValid() =>
        A > 0 && B > 0 && C > 0 &&
        A + B > C && A + C > B && B + C > A;
}